package com.jeesite.modules.kj.api.vo;


import com.jeesite.common.entity.Page;
import com.jeesite.modules.kj.api.vo.responseVo.base.BaseResponseVo;

import java.util.ArrayList;
import java.util.List;

public class DataListPageVo<T extends BaseResponseVo> {
    private List<T> list;
    private int pageNo;
    private int pageSize;
    private long count;

    public DataListPageVo() {
    }

    public DataListPageVo(Page page) {
        this.list = page.getList();
        this.count = page.getCount();
        this.pageNo = page.getPageNo();
        this.pageSize = page.getPageSize();
    }

    public DataListPageVo(Page page, Class < T > clazz) {

        List pageList = page.getList();
        this.list = new ArrayList<>();
        for (Object data: pageList
             ) {
            try {
                T obj = clazz.newInstance();
                obj.setEntity(data);
                this.list.add(obj);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        this.count = page.getCount();
        this.pageNo = page.getPageNo();
        this.pageSize = page.getPageSize();
    }

    public DataListPageVo(List<T> list, int pageNo, int pageSize, int count) {
        this.list = list;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.count = count;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }
}
